package com.ddwl.message.controller;

import com.ddwl.common.annotation.Auth;
import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.controller.BaseController;
import com.ddwl.message.service.WsMsgService;
import com.ddwl.schema.bo.message.WebSocketMessageBo;
import com.ddwl.schema.vo.base.RestVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author hemiaojun
 * @Date 2020/12/11 11:58
 */
@RestController
@RequestMapping("/webSocket")
@Api(tags="webSocket消息推送")
public class WebSocketController extends BaseController {

    @Resource
    private WsMsgService webSocketServer;

    @PostMapping("/push")
    @Auth(product = {BaseEnum.ProductEnum.API, BaseEnum.ProductEnum.CONSOLE})
    @ApiOperation("webSocket推送消息到web端")
    public RestVo<String> pushToWeb(@RequestBody WebSocketMessageBo bo){
        return RestVo.ok(webSocketServer.pushMessage(bo));
    }

    @PostMapping("/changeId")
    @ApiOperation("把id反转成时间戳")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo changeId(){
        webSocketServer.changeId();
        return RestVo.ok();
    }

}
